$(function() {
	var tabs = $('#tabs'),
	tabLinks = tabs.find('a.tab');
	
	tabLinks.click(function(e, slideshow) {
		var tabLink = $(this);
		tabLinks.filter('.active').removeClass('active');
		tabLink.addClass('active');
		
		tabs.children('.tab-content:visible').fadeOut(function() {
			$(tabLink.attr('href')).fadeIn();
		});
		
		if(!slideshow) {
			clearInterval(window.tabTimer);
		}

		if(e) {
			e.preventDefault();
		}
	});
	
	$.getJSON("http://blog.primefaces.org/?feed=json&jsonp=?", function(data) { 
		var news = $('#news'); 
			for(var i = 0; i < 2; i++) { 
				var entry = data[i],
				content = '<div class="post">';
				content += '<strong class="entry-title">' + entry.title + '</strong>';
				content += '<p>' + entry.excerpt + '</p>';
				content += '<div class="post-frame"><em class="date">' + entry.date + '</em></div>';
				content += '</div>';
				
				news.append(content);
			} 
			
		//news.append('<span class="view"><a href="http://blog.primefaces.org">view all</a></span>');
	});
	
	//slideshow
	var i = 1;
	window.tabTimer = setInterval(function() {
		i++;
		if(i == 7) {
			i = 1;
		}
		
		$('#hdr_tab' + i).trigger('click', [true]);
	},5000);
});